package com.hcy.driverapi.controller;

import com.hcy.orderclient.OrderBaseClient;
import com.hcy.orderclient.OrderForDriverClient;
import com.hcy.ordermodel.dto.request.DriveComputerOrderRequestDTO;
import com.hcy.ordermodel.dto.request.DriverOrderListRequestDTO;
import com.hcy.ordermodel.dto.request.DriverOrderRequestDTO;
import com.hcy.ordermodel.dto.response.OrderInfoResponseDTO;
import com.hcy.rabbitbasicmodel.enums.Code;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import com.hcy.rabbitbasicmodel.model.ReturnResult;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author huchenying
 * @Description
 * @Date 2021/12/30 19:02
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    OrderForDriverClient orderForDriverClient;

    @Autowired
    OrderBaseClient orderBaseClient;


    /**
     * @Author huchenying
     * @Description 获取订单详细信息
     * @Date  2021/12/30 19:01
     **/
    @PostMapping("/orderDetails")
    public ReturnResult orderDetails(@RequestBody @Validated DriverOrderRequestDTO requestDTO){
        logger.info("orderDetails start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<OrderInfoResponseDTO> responseData = orderForDriverClient.orderDetails(requestDTO);
        if(responseData.getCode() == Code.Success){
            return ReturnResult.success().setData(responseData.getData());
        }
        return ReturnResult.fail(responseData.getMsg());
    }

    /**
     * @Author huchenying
     * @Description 预估订单
     * @Date  2021/12/30 19:01
     **/
    @PostMapping("/computerOrder")
    public ReturnResult computerOrder(@RequestBody @Validated DriveComputerOrderRequestDTO requestDTO){
        logger.info("computerOrder start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<OrderInfoResponseDTO> responseData = orderBaseClient.computerOrder(requestDTO);
//        responseData.getData().setD
        if(responseData.getCode() == Code.Success){
            return ReturnResult.success().setData(responseData.getData());
        }
        logger.error("result -> {}",responseData.getMsg());
        return ReturnResult.fail(responseData.getMsg());
    }

    /**
     * @Author huchenying
     * @Description 获取已接单信息
     * @Date 2022/4/15 21:13
     **/
    @PostMapping("/getOrderList")
    public ReturnResult getOrderList(@RequestBody @Validated DriverOrderListRequestDTO requestDTO){
        logger.info("getOrderList start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<List<OrderInfoResponseDTO>> responseData = orderForDriverClient.getOrderList(requestDTO);
        if(responseData.getCode() == Code.Success){
            return ReturnResult.success().setData(responseData.getData());
        }
        logger.error("result -> {}",responseData.getData());
        return ReturnResult.fail("获取行程单失败");
    }
}
